#include<iostream>
#include<string>
#include"Date.h"
#include"Book.h"

using namespace std;

Book::Book(string num0, string title0, string author0, string press0,
	int py, int pm, int pd, float price, int sn):
	num(num0), title(title0), author(author0), press(press0),
	publishDate(py, pm ,pd), price(price), storeNum(sn)
{
	if (!publishDate.isDateRight())
	{
		publishDate = Date(2023, 1, 1);
	}
}

void Book::setNum(string num0)
{
	num = num0; 
}

void Book::setTitle(string title0)
{
	title = title0; 
}

void Book::setAuthor(string author0)
{
	author = author0; 
}

void Book::setPress(string press0)
{
	press = press0;
}

void Book::setKind(string kind0)
{
	kind = kind0;
}

void Book::setPublishDate(int by, int bm, int bd)
{
	Date* date0 = new Date(bd, bm, by);

	if (date0->isDateRight())
	{
		publishDate = *date0;
	}

	delete date0;
}

void Book::setStoreNum(int sn)
{
	storeNum = sn; 
}

void Book::setPrice(float pr)
{
	price = pr; 
}

string Book::getNum() const
{
	return num; 
}

int Book::getStoreNum() const
{
	return storeNum;
}

float Book::getPrice() const
{
	return price;
}

string Book::getTitle() const
{
	return title; 
}

string Book::getAuthor() const
{
	return author; 
}

string Book::getPress() const
{
	return press; 
}

string Book::getKind() const
{
	return kind;
}

Date Book::getPublishdate() const
{
	return publishDate; 
}

void Book::showBook() const
{
	{
		cout << num << "\t" << title << "\t" << author << "\t" << press << "\t";
		publishDate.showDate();
		cout << "\t" << price << "\t" << storeNum << endl;
	}
}



BorrowedBook::BorrowedBook(const Book& bb, string num, string name, const Date& bd, int bt):
	Book(bb)
{
	readerNum = num;
	readerName = name;
	borrowedDate = bd;
	returnDate = Date(borrowedDate, bt);
}

void BorrowedBook::setReaderNum(string num)
{
	readerNum = num;
}

void BorrowedBook::setReaderName(string name)
{
	readerName = name;
}

void BorrowedBook::setBorrowedDate(int y, int m, int d)
{
	borrowedDate = Date(y, m, d);
}

void BorrowedBook::setReturnDate(int y, int m, int d)
{
	returnDate = Date(y, m, d);
}

string BorrowedBook::getReaderNum()
{
	return readerNum;
}

string BorrowedBook::getReaderName()
{
	return readerName;
}

Date BorrowedBook::getBorrowedDate()
{
	return borrowedDate;
}

Date BorrowedBook::getReturnDate()
{
	return returnDate;
}

void BorrowedBook::showInfo()
{
	cout << readerNum << "\t" << readerName << "\t" << num << "\t" << title << "\t";

	borrowedDate.showDate();
	cout << "/t";
	returnDate.showDate();
	cout << endl;
}

bool BorrowedBook::isLate(const Date& dateNow)
{
	if (dateNow.getYear() == returnDate.getYear())
	{
		if (dateNow.getMonth() == returnDate.getMonth())
		{
			if (dateNow.getDay() <= returnDate.getDay())
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		else if (dateNow.getMonth() < returnDate.getMonth())
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else if (dateNow.getYear() < returnDate.getYear())
	{
		return false;
	}
	else
	{
		return true;
	}
}
